package com.example.lib_log

import com.example.lib_log.logger.LogcatLogger


class Logger private constructor(private val TAG:String,private val level:LoggerLevel,private val loggerStrategy:LoggerStrategy,private val isDebug:Boolean,private val saveUrl:String){
    private var logger:ILogger
    init {
        logger = getLogger()
    }
    constructor(builder: Builder):this(
        builder.TAG,
        builder.level,
        builder.loggerStrategy,
        builder.isDebug,
        builder.saveUrl
    )
    /**
     * 创建Logger
     */
    fun getLogger():ILogger{
        when(loggerStrategy){
            LoggerStrategy.FILE -> throw IllegalArgumentException("该方案未实现")
            LoggerStrategy.NET -> throw IllegalArgumentException("该方案未实现")
            LoggerStrategy.LOGCAT -> logger = LogcatLogger()
        }
        logger.setLogLevel(level)
        logger.setDebug(isDebug)
        logger.setLogTAG(TAG)
        logger.setSaveUrl(saveUrl)
        return logger
    }
    /**
     * 输出Debug log
     */
    fun d(Tag:String,log:String){
        logger.d(Tag,log)
    }

    /**
     * 输出Warn log
     */
    fun w(Tag:String,log:String){
        logger.w(Tag,log)
    }

    /**
     * 输出Verbose log
     */
    fun v(Tag:String,log:String){
        logger.v(Tag,log)
    }

    /**
     * 输出Error log
     */
    fun e(Tag:String,log:String){
        logger.e(Tag,log)
    }
    /**
     * 输出Info log
     */
    fun i(Tag:String,log:String){
        logger.i(Tag,log)
    }



    class Builder{
        var TAG:String = "默认TAG"
        var level:LoggerLevel = LoggerLevel.Debug
        var loggerStrategy: LoggerStrategy = LoggerStrategy.LOGCAT
        var isDebug:Boolean = true
        var saveUrl:String = "默认路径"

        fun setTAG(TAG:String):Builder{
            this.TAG = TAG
            return this
        }
        fun setLevel(level:LoggerLevel):Builder{
            this.level = level
            return this
        }

        fun setLoggerType(loggerStrategy: LoggerStrategy):Builder{//设置策略
            this.loggerStrategy = loggerStrategy
            return this
        }

        fun isDebug(isDebug: Boolean):Builder{
            this.isDebug = isDebug
            return this
        }


        fun setSaveUrl(saveUrl: String):Builder{
            this.saveUrl = saveUrl
            return this
        }

        fun build():Logger{
            return Logger(this)
        }
    }
}